package com.shxy.entity.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.shxy.util.converter.AbstractEnumConverter;
import com.shxy.util.converter.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.lang.Nullable;

/**
 * 地区枚举
 */
@Getter
@AllArgsConstructor
public enum DistrictEnum implements IEnum<String> {
    JING("11", "北京市"),
    JINN("12","天津市"),
    JI("13","河北省"),
    JIN("14","山西省"),
    MENG("15","内蒙古自治区"),
    LIAO("21","辽宁省"),
    JII("220","吉林省"),
    HEI("23","黑龙江省"),
    HU("31","上海市"),
    SU("32","江苏省"),
    ZHE("33","浙江省"),
    WAN("34","安徽省"),
    MIN("35","福建省"),
    GAN("36","江西省"),
    LU("37","山东省"),
    YU("41","河南省"),
    E("42","湖北省"),
    XIANG("43","湖南省"),
    YUE("44","广东省"),
    GUI("45","广西壮族自治区"),
    QIONG("46","海南省"),
    YUU("50","重庆市"),
    CHUAN("51","四川省"),
    GUIZ("52","贵州省"),
    YUN("53","云南省"),
    ZANG("54","西藏自治区"),
    SHAN("61","陕西省"),
    GANA("62","甘肃省"),
    QING("63","青海省"),
    NING("64","宁夏回族自治区"),
    XIN("65","新疆维吾尔自治区"),
    TAIPEI("71","台湾省"),
    HONGKONG("81","香港特别行政区"),
    MACAU("82","澳门特别行政区")

    ;
    private String code;
    private String name;

    /**
     * 类型转换器
     */
    public static class Converter extends AbstractEnumConverter<DistrictEnum, String> {
        public Converter() {
            super(DistrictEnum.class);
        }
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    @Nullable
    public static DistrictEnum resolve(String name) {
        for(DistrictEnum districtEnum: DistrictEnum.values()) {
            if(name.equals(districtEnum.getName())){
                return districtEnum;
            }
        }
        return null;
    }
}
